package cn.tedu.spring.example;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class TestUser {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        /*
            方式1：通过 new 关键字创建对象;
         */
        User user1 = new User();
        user1.run();

        /*
        方式2：通过反射方式创建对象;
         */
        Class zz = Class.forName("cn.tedu.spring.example.User");
        User user2 = (User) zz.newInstance();

        /*
        方式3：通过Spring框架创建对象
            1.创建IoC容器;
            2.获取对象;
            3.调用方法测试.
         */
        ApplicationContext contxt = new AnnotationConfigApplicationContext("cn.tedu.spring.example");
        User user3 = contxt.getBean(User.class);
        user3.run();

    }
}
